package tech.heptagram.staff.cas.controller.view;


import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import tech.heptagram.core.common.rest.ResponseResult;
import tech.heptagram.staff.cas.common.CurrentUserUtil;
import tech.heptagram.staff.cas.domain.StaffEntity;
import tech.heptagram.staff.cas.domain.po.Menu;

/**
 * @author zilaiye
 * @date 2017/12/7
 */
@RestController
@RequestMapping("/api/view/sys")
public class CasCurrentUserApiController {

    @PostMapping("/user/principal")
    @ResponseBody
    public ResponseResult<Map> getCurrentPrincipal(@RequestParam("mid") Integer mid) {
        StaffEntity staffVo = CurrentUserUtil.getCurrentUser();

        Map<String, Object> result = new HashMap<>();

        result.put("currentStaff", staffVo);
        result.put("trueName", staffVo.getTrueName());
        result.put("nickName", staffVo.getNickName());
        result.put("avatarUrl", staffVo.getAvatarUrl());

        List<Menu> lstOperates = CurrentUserUtil.getCurrentUserOperates(mid);
        result.put("operates", lstOperates);

        return new ResponseResult<>(result);
    }
}
